<?php
class login extends base{
	public $layout = "";

	public function init(){
		parent::init();

		$this->modelObj = D('site_admin');
	}

	public function index(){
		if($this->isAjax()){
			$data = $this->postData('data');

			$res = $this->modelObj->check_login($data['username'],$data['password']);
	        if($res){
	        	$_SESSION["site_admin"] = $res['admin'];
		    	// $_SESSION['logintime'] = time();
		    	// set_cookie('admin_mnm',$admin['username']);
	            // $this->modelObj->up_time($admin['id']);
				$this->renderSuccess('登录成功', '/site/main/index');
	        }else{
	            $this->renderError('登录失败');
	        }

		}
	}


	// 退出
	public function logout(){
		// 这里是PHP.net关于删除SESSION的方法
		$_SESSION = array();
		if (isset($_COOKIE[session_name()])) {set_cookie(session_name(), '', time()-42000, '/');}
		session_destroy();
		$this->redirect("/login/index");
	}

}